#include "MoveablePlatformElement.hpp"

MoveablePlatformElement::MoveablePlatformElement(const b2Vec2* vertices, int numberOfVertices, const b2Vec2 start, const b2Vec2 end, float velocity, RoomElement* room, b2World* world) : ActionableElement(false) {
    b2BodyDef bodyDefinition;
    bodyDefinition.userData = this;
    bodyDefinition.position = start;
    bodyDefinition.type = b2_dynamicBody;
    bodyDefinition.bullet = true;
    bodyDefinition.fixedRotation = true;

    b2ChainShape shape;
    shape.CreateChain(vertices, numberOfVertices);

    b2FixtureDef fixtureDefinition;
    fixtureDefinition.shape = &shape;
    fixtureDefinition.density = 1.0f;

    this->body = world->CreateBody(&bodyDefinition);
    this->body->CreateFixture(&fixtureDefinition);

    /*this->start = new b2Vec2();
    this->start->Set(start.x, start.y);

    this->end = new b2Vec2();
    this->end->Set(end.x, end.y);

    this->linearVelocity = new b2Vec2();
    this->linearVelocity->Set(end.x, end.y);
    this->linearVelocity->operator -=(start);
    this->linearVelocity->Normalize();

    b2PrismaticJointDef jointDefinition;
    jointDefinition.Initialize(this->body, room->body, this->body->GetWorldCenter(), *this->linearVelocity);
    jointDefinition.enableLimit = false;
    jointDefinition.enableMotor = false;
    //world->CreateJoint(&jointDefinition);

    this->linearVelocity->operator *=(velocity);*/
}

bool MoveablePlatformElement::isMoveablePlatform() {
    return true;
}

void MoveablePlatformElement::turnOff() {
    this->shouldBeMoved = true;
}

void MoveablePlatformElement::turnOn() {
    this->shouldBeMoved = true;
}
